﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using DLL;
using System.Text.RegularExpressions;

public partial class Admin_Congty_Themcongty : System.Web.UI.Page
{
    luuliDataContext db = new luuliDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button10_Click(object sender, EventArgs e)
    {
        if (!IsValidEmail(TextBox3.Text.Trim()))
        {
            Label3.Visible = true;
        }

        String fileName = FileUpload1.FileName.ToString();
        String path = "~/Hinh/" + fileName;
        string hinh = path;
        if (fileName.ToString() != "")
        {
            //hinh---------------------------------------------------------------------
            //FileUpload1.GetType();


            //Lưu file
            String path1 = Server.MapPath(path);
            FileUpload1.PostedFile.SaveAs(path1);

        }

        else
            Label2.Text = "Nên có hình đại diện";
        Label2.Visible = true;
        try
        {

            db.themcongty(TextBox1.Text, TextBox2.Text, TextBox3.Text, TextBox4.Text, TextBox5.Text, hinh, TextBox6.Text, DropDownList1.SelectedValue.ToString());
        }
        catch (Exception b)
        {


        }
    }

    public bool IsValidEmail(string email)
    {
        try
        {
            int nFirt = int.Parse(email.Substring(0, 1));
            return false;
        }
        catch
        {
            string pattern = @"^[_a-zA-Z0-9][_.a-zA-Z0-9]*@[-.a-zA-Z0-9]+(\.[_.a-zA-Z0-9]+)*\.
    (com|edu|info|gov|int|mil|net|org|biz|name|museum|coop|aero|pro|tv|vn|[a-zA-Z]{2})$";
            //Regular expression object
            Regex check = new Regex(pattern, RegexOptions.IgnorePatternWhitespace);
            //boolean variable to return to calling method
            bool valid = false;

            //make sure an email address was provided
            if (string.IsNullOrEmpty(email))
            {
                valid = false;
            }
            else
            {
                //use IsMatch to validate the address
                valid = check.IsMatch(email.ToLower());
            }
            //return the value to the calling method
            return valid;
        }
    }
    //private void txtTo_TextChanged(object sender, EventArgs e)
    //{
    //    if (!IsValidEmail(txtMailAdd.Text.Trim()))
    //    {

    //        this.btnSend.Enabled = false;
    //    }
    //    else
    //    {
    //        this.btnSend.Enabled = true;
    //    }
    //}
}